<template>
  <div id="recommend">
        <div class="main-bar-view">

            <img src="../assets/images/logo.png" class="logo" @click="returnTo">

            <div class="search-entry">


                <img src="../assets/images/search-icon.svg" class="search-icon">

                <input class="search-input" placeholder="请输入搜索的内容">
            </div>
            <div class="right-view" >

                <a class="ant-dropdown-link ant-dropdown-trigger" v-if="isLogged" @click="toUserCenter">
                  <img src="../assets/images/avatar.jpg" class="self-img">
                </a>
                <button class="login btn hidden-sm" @click="toLoginPage" v-else>登录</button>
                <div class="right-icon">
                    <img src="../assets/images/message-icon.svg" @click="toMessage">
                </div>
            </div>
        </div>
        <div class="content">
          <div>
            <div style="display: flex; justify-content: flex-start;height: 30px">
              <i class="el-icon-user-solid" style="font-size: 25px"></i>
            </div>
            <el-row>
              <el-col :span="20"> <!-- 这里假设你希望输入框占据大部分空间，所以给它20个栅格 -->
                <el-input
                  type="textarea"
                  autosize
                  placeholder="请输入描述"
                  v-model="question">
                </el-input>
              </el-col>
              <el-col :span="4"> <!-- 剩余的空间给按钮，这里假设是4个栅格 -->
                <el-button type="primary" @click="getRecommend">获取推荐</el-button>
              </el-col>
            </el-row>
            <div style="margin: 20px 0;"></div>
            <div style="display: flex; justify-content: flex-start;height: 30px">
              <i class="el-icon-cpu" style="font-size: 25px"></i>
            </div>
            <el-input
              type="textarea"
              :autosize="{ minRows: 10}"
              placeholder="AI推荐"
              v-model="answer"
              readonly>
            </el-input>
          </div>
        </div>
  </div>
</template>

<script>
import Cookies from "js-cookie";
import axios from "axios";

export default {
  data(){
    return {
      question:'',
      answer:'',
    }
  },
  mounted() {
  },
  methods:{
    toLoginPage(){
        this.$router.push('/login');
    },
    getRecommend(){
      console.log(this.question)
      if (this.question !== undefined && this.question !== '') {
        this.answer = '请稍后'
        axios.post('http://127.0.0.1:5000/v1/books/returnGPTRecommend',
            {'content': this.question},
            {headers: {'Content-Type': 'application/json'}})
            .then(response => {
              if (response.data.status === 200) {
                this.answer = response.data.data;
              } else {
                this.answer = '获取建议失败';
              }
            })
      }
      else
        this.$message.error('请输入描述')
    },
    returnTo(){
      this.$router.push({name: 'userborrowview'})
    },
    toUserCenter(){
      this.$router.push('/person')
    },
    toMessage(){
      this.$router.push('/notice')
    }
  },
  computed:{
    isLogged(){
      const token = Cookies.get('token');
      console.log(token)
      const isLogged = token !== undefined && token !== '';
      console.log(isLogged)
      return isLogged;
    }
  }

}
</script>

<style>
.main-bar-view {
    position: fixed;
    top: 0;
    left: 0;
    height: 56px;
    width: 100%;
    background: #fff;
    border-bottom: 1px solid #cedce4;
    padding-left: 48px;
    z-index: 16;
    display: -webkit-box;
    display: -ms-flexbox;
    display: flex;
    -webkit-box-orient: horizontal;
    -webkit-box-direction: normal;
    -ms-flex-direction: row;
    flex-direction: row;
    -webkit-box-align: center;
    -ms-flex-align: center;
    align-items: center;
}
.main-bar-view .logo {
    width: 30px;
    height: auto;
    margin-right: 24px;
}
.search-entry {
    display: flex;
    position: relative;
    width: 400px;
    min-width: 200px;
    height: 32px;
    background: #ecf3fc;
    padding: 0 12px;
    border-radius: 16px;
    font-size: 0;
    cursor: pointer;
}
.search-entry .search-icon{
  justify-content: flex-start;
  width: 18px;
}
.search-entry img{
  justify-content: flex-start;
  max-width: 100%;
  height: auto;
}
.search-input{
    position: absolute;
    top: -5px;
    left: 40px;
    width: auto;
    height: 24px;
    border: 0;
    outline: none;
    color: #000;
    background: #ecf3fc;
    font-size: 14px;
    padding: 0;
}
.right-view{
    -webkit-text-size-adjust: 100%;
    -webkit-tap-highlight-color: rgba(0,0,0,0);
    --antd-wave-shadow-color: #1890ff;
    color: rgba(0,0,0,.65);
    font-size: 14px;
    font-variant: tabular-nums;
    line-height: 1.5;
    font-feature-settings: "tnum";
    font-family: Avenir,Helvetica,Arial,sans-serif;
    box-sizing: border-box;
    padding-right: 80px;
    -webkit-box-flex: 1;
    flex: 1;
    display: flex;
    -webkit-box-orient: horizontal;
    -webkit-box-direction: normal;
    flex-direction: row;
    gap: 20px;
    -webkit-box-pack: end;
    justify-content: flex-end;

}
.self-img {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    vertical-align: middle;
    cursor: pointer;
  }
a{
    --antd-wave-shadow-color: #1890ff;
    font-size: 14px;
    font-variant: tabular-nums;
    font-feature-settings: "tnum";
    font-family: Avenir,Helvetica,Arial,sans-serif;
    box-sizing: border-box;
    color: #1890ff;
    text-decoration: none;
    background-color: transparent;
    outline: none;
    cursor: pointer;
    transition: color .3s;
    touch-action: manipulation;
    line-height: 32px;
    width: 60px;

}
.right-view .btn {
    background: #4684e2;
    font-size: 14px;
    color: #fff;
    border-radius: 32px;
    text-align: center;
    width: 66px;
    height: 32px;
    line-height: 32px;
    vertical-align: middle;
    margin-left: 32px;
}
.right-view button {
    outline: none;
    border: none;
    cursor: pointer;
}
.right-view img[data-v-97d8b1e2] {
    cursor: pointer;
}
.right-view .right-icon img{
    margin-right: 20px;
    position: relative;
    width: 24px;
    margin: 4px 0 0 4px;
    cursor: pointer;
    display: inline-block;
    font-size: 0;
}
#recommend{
    -webkit-text-size-adjust: 100%;
    -webkit-tap-highlight-color: rgba(0,0,0,0);
    --antd-wave-shadow-color: #1890ff;
    color: rgba(0,0,0,.65);
    font-size: 14px;
    font-variant: tabular-nums;
    line-height: 1.5;
    font-feature-settings: "tnum";
    box-sizing: border-box;
    font-family: Avenir,Helvetica,Arial,sans-serif;
    height: 100vh;
}
.content{
    position: relative;
    --antd-wave-shadow-color: #1890ff;
    color: rgba(0, 0, 0, .65);
    font-size: 14px;
    font-variant: tabular-nums;
    line-height: 1.5;
    font-feature-settings: "tnum";
    font-family: Avenir, Helvetica, Arial, sans-serif;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    width: 1100px;
    margin: 4px auto;
    top: 100px;
}
</style>